# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
   # We want to show validation errors on the right of the corresponding field each
  ActionView::Base.field_error_proc = Proc.new do |html, instance|
    %{<div class="error-with-field">#{html} <small class="error">&bull; #{[instance.error_message].flatten.first}</small></div>}
  end

  class AccessDenied < StandardError; end
  around_filter :catch_errors

  # Pick a unique cookie name to distinguish our session data from others'
  before_filter :login_from_cookie
  session :session_key => '_kinotable_session_id'


   def catch_errors
    begin

      yield

    rescue AccessDenied
      flash[:notice] = "У вас не хватает полномочий, вы предстанете перед трибуналом."
      redirect_to '/'
    rescue ActiveRecord::RecordNotFound
      flash[:notice] = "Не могу найти того, что вы хотите."
      redirect_to '/'
    end
   end

end
